<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="测站代码" prop="statCd">
        <el-input
          v-model="queryParams.statCd"
          placeholder="请输入测站代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="曲线名称" prop="curvNm">
        <el-input
          v-model="queryParams.curvNm"
          placeholder="请输入曲线名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="启用时间" prop="enabTm">
        <el-date-picker clearable
          v-model="queryParams.enabTm"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择启用时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="点序号" prop="ptNo">
        <el-input
          v-model="queryParams.ptNo"
          placeholder="请输入点序号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="水位" prop="curLevel">
        <el-input
          v-model="queryParams.curLevel"
          placeholder="请输入水位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="流量" prop="curFlow">
        <el-input
          v-model="queryParams.curFlow"
          placeholder="请输入流量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="系数1" prop="k1">
        <el-input
          v-model="queryParams.k1"
          placeholder="请输入系数1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="系数2" prop="k2">
        <el-input
          v-model="queryParams.k2"
          placeholder="请输入系数2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="系数3" prop="k3">
        <el-input
          v-model="queryParams.k3"
          placeholder="请输入系数3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="系数4" prop="k4">
        <el-input
          v-model="queryParams.k4"
          placeholder="请输入系数4"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="系数5" prop="k5">
        <el-input
          v-model="queryParams.k5"
          placeholder="请输入系数5"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="常量" prop="b">
        <el-input
          v-model="queryParams.b"
          placeholder="请输入常量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="水位上限" prop="topZ">
        <el-input
          v-model="queryParams.topZ"
          placeholder="请输入水位上限"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="水位下限" prop="botZ">
        <el-input
          v-model="queryParams.botZ"
          placeholder="请输入水位下限"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="淤积深度" prop="siltDepth">
        <el-input
          v-model="queryParams.siltDepth"
          placeholder="请输入淤积深度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="启动状态" prop="enabType">
        <el-select v-model="queryParams.enabType" placeholder="请选择启动状态" clearable>
          <el-option
            v-for="dict in dict.type.enab_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="阶数" prop="rank">
        <el-input
          v-model="queryParams.rank"
          placeholder="请输入阶数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="插入时间" prop="insertTime">
        <el-date-picker clearable
          v-model="queryParams.insertTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择插入时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="备注" prop="nt">
        <el-input
          v-model="queryParams.nt"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['waterManagement:RelZQ:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['waterManagement:RelZQ:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['waterManagement:RelZQ:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['waterManagement:RelZQ:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="RelZQList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="测站代码" align="center" prop="statCd">
      </el-table-column>
      <el-table-column label="曲线名称" align="center" prop="curvNm">
      </el-table-column>
      <el-table-column label="启用时间" align="center" prop="enabTm" width="180">
      </el-table-column>
      <el-table-column label="点序号" align="center" prop="ptNo">
      </el-table-column>
      <el-table-column label="水位" align="center" prop="curLevel">
      </el-table-column>
      <el-table-column label="流量" align="center" prop="curFlow">
      </el-table-column>
      <el-table-column label="系数1" align="center" prop="k1">
      </el-table-column>
      <el-table-column label="系数2" align="center" prop="k2">
      </el-table-column>
      <el-table-column label="系数3" align="center" prop="k3">
      </el-table-column>
      <el-table-column label="系数4" align="center" prop="k4">
      </el-table-column>
      <el-table-column label="系数5" align="center" prop="k5">
      </el-table-column>
      <el-table-column label="常量" align="center" prop="b">
      </el-table-column>
      <el-table-column label="水位上限" align="center" prop="topZ">
      </el-table-column>
      <el-table-column label="水位下限" align="center" prop="botZ">
      </el-table-column>
      <el-table-column label="淤积深度" align="center" prop="siltDepth">
      </el-table-column>
      <el-table-column label="启动状态" align="center" prop="enabType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.enab_type" :value="scope.row.enabType"/>
        </template>
      </el-table-column>
      <el-table-column label="阶数" align="center" prop="rank">
      </el-table-column>
      <el-table-column label="插入时间" align="center" prop="insertTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.insertTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="nt">
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['waterManagement:RelZQ:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['waterManagement:RelZQ:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改水位流量关系对照对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="测站代码" prop="statCd">
          <el-input v-model="form.statCd" placeholder="请输入测站代码" />
        </el-form-item>
        <el-form-item label="曲线名称" prop="curvNm">
          <el-input v-model="form.curvNm" placeholder="请输入曲线名称" />
        </el-form-item>
        <el-form-item label="启用时间" prop="enabTm">
          <el-date-picker clearable
            v-model="form.enabTm"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择启用时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="点序号" prop="ptNo">
          <el-input v-model="form.ptNo" placeholder="请输入点序号" />
        </el-form-item>
        <el-form-item label="水位" prop="curLevel">
          <el-input v-model="form.curLevel" placeholder="请输入水位" />
        </el-form-item>
        <el-form-item label="流量" prop="curFlow">
          <el-input v-model="form.curFlow" placeholder="请输入流量" />
        </el-form-item>
        <el-form-item label="系数1" prop="k1">
          <el-input v-model="form.k1" placeholder="请输入系数1" />
        </el-form-item>
        <el-form-item label="系数2" prop="k2">
          <el-input v-model="form.k2" placeholder="请输入系数2" />
        </el-form-item>
        <el-form-item label="系数3" prop="k3">
          <el-input v-model="form.k3" placeholder="请输入系数3" />
        </el-form-item>
        <el-form-item label="系数4" prop="k4">
          <el-input v-model="form.k4" placeholder="请输入系数4" />
        </el-form-item>
        <el-form-item label="系数5" prop="k5">
          <el-input v-model="form.k5" placeholder="请输入系数5" />
        </el-form-item>
        <el-form-item label="常量" prop="b">
          <el-input v-model="form.b" placeholder="请输入常量" />
        </el-form-item>
        <el-form-item label="水位上限" prop="topZ">
          <el-input v-model="form.topZ" placeholder="请输入水位上限" />
        </el-form-item>
        <el-form-item label="水位下限" prop="botZ">
          <el-input v-model="form.botZ" placeholder="请输入水位下限" />
        </el-form-item>
        <el-form-item label="淤积深度" prop="siltDepth">
          <el-input v-model="form.siltDepth" placeholder="请输入淤积深度" />
        </el-form-item>
        <el-form-item label="启动状态" prop="enabType">
          <el-select v-model="form.enabType" placeholder="请选择启动状态">
            <el-option
              v-for="dict in dict.type.enab_type"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="阶数" prop="rank">
          <el-input v-model="form.rank" placeholder="请输入阶数" />
        </el-form-item>
        <el-form-item label="插入时间" prop="insertTime">
          <el-date-picker clearable
            v-model="form.insertTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择插入时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="nt">
          <el-input v-model="form.nt" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRelZQ, getRelZQ, delRelZQ, addRelZQ, updateRelZQ } from "@/api/waterManagement/RelZQ";

export default {
  name: "RelZQ",
  dicts: ['enab_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 水位流量关系对照表格数据
      RelZQList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        statCd: null,
        curvNm: null,
        enabTm: null,
        ptNo: null,
        curLevel: null,
        curFlow: null,
        k1: null,
        k2: null,
        k3: null,
        k4: null,
        k5: null,
        b: null,
        topZ: null,
        botZ: null,
        siltDepth: null,
        enabType: null,
        rank: null,
        insertTime: null,
        nt: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询水位流量关系对照列表 */
    getList() {
      this.loading = true;
      listRelZQ(this.queryParams).then(response => {
        this.RelZQList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        statCd: null,
        curvNm: null,
        enabTm: null,
        ptNo: null,
        curLevel: null,
        curFlow: null,
        k1: null,
        k2: null,
        k3: null,
        k4: null,
        k5: null,
        b: null,
        topZ: null,
        botZ: null,
        siltDepth: null,
        enabType: null,
        rank: null,
        insertTime: null,
        nt: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.statCd)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加水位流量关系对照";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const statCd = row.statCd || this.ids
      getRelZQ(statCd).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改水位流量关系对照";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.statCd != null) {
            updateRelZQ(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRelZQ(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const statCds = row.statCd || this.ids;
      this.$modal.confirm('是否确认删除水位流量关系对照编号为"' + statCds + '"的数据项？').then(function() {
        return delRelZQ(statCds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('waterManagement/RelZQ/export', {
        ...this.queryParams
      }, `RelZQ_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
